package cn.lingyangwl.agile.system.controller;

import cn.lingyangwl.agile.system.model.entity.RamModule;
import cn.lingyangwl.agile.system.model.rqrs.ram.RamModuleListReq;
import cn.lingyangwl.framework.core.response.Resp;
import cn.lingyangwl.agile.system.model.rqrs.ram.RamModuleUpdateReq;
import cn.lingyangwl.agile.system.service.RamModuleService;
import cn.lingyangwl.agile.ram.ActionType;
import cn.lingyangwl.agile.ram.RamResource;
import io.swagger.annotations.Api;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 资源模块
 * 
 * @author shenguangyang
 */
@Api(tags = "资源模块")
@RestController
@RequestMapping("/resourceModule")
public class RamModuleController {
    @Resource
    private RamModuleService ramModuleService;

    /**
     * 通过id查找 资源模块
     */
    @RamResource(action = "sys:resourceModule:get", name = "获取资源模块", type = ActionType.READ)
    @GetMapping("/getResourceModule")
    public Resp<RamModule> getResourceModuleById(@RequestParam(value = "id") Long id) {
        return Resp.ok(ramModuleService.getById(id));
    }

    @RamResource(action = "sys:resourceModule:list", name = "查找资源模块列表", type = ActionType.READ)
    @GetMapping("/listResourceModule")
    public Resp<List<RamModule>> listResourceModule(RamModuleListReq req) {
        return Resp.ok(ramModuleService.listResourceModule(req));
    }
  
    /**
     * 保存 资源模块
     */
    @RamResource(action = "sys:resourceModule:save", name = "保存资源模块", type = ActionType.WRITE)
    @PostMapping("/saveResourceModule")
    public Resp<?> saveResourceModule(@Validated @RequestBody RamModule rq) {
        return Resp.ok(ramModuleService.saveResourceModule(rq));
    }
  
    /**
     * 更新 资源模块
     */
    @RamResource(action = "sys:resourceModule:update", name = "更新资源模块", type = ActionType.WRITE)
    @PostMapping("/updateResourceModule")
    public Resp<?> updateResourceModuleById(@RequestBody RamModuleUpdateReq rq) {
        return Resp.ok(ramModuleService.updateResourceModule(rq));
    }
  
    /**
     * 批量删除 资源模块
     */
    @RamResource(action = "sys:resourceModule:delete", name = "删除资源模块", type = ActionType.WRITE)
    @DeleteMapping("/batchDeleteResourceModule")
    public Resp<?> deleteBatch(@RequestParam(value = "ids") List<Long> ids) {
        return Resp.ok(ramModuleService.deleteResourceModuleByIds(ids));
    }
}
